<?php
	require_once $_SERVER['DOCUMENT_ROOT'] .
		'/SAGER/model/interfaces/ILegalClientAccessDao.php';
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/model/interfaces/IConnectionAccessDao.php';
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/model/factory/ConnectionFactory.php';
	
	error_reporting (E_ALL ^ E_NOTICE);
	
	$debug = $_SESSION['debug'];

	class  MySqlLegalClientAccessDao implements ILegalClientAccessDao {
   		/**
		 * Constructor of the legal client dao
		 */
	 	public function __construct () {}
		
		/**
		 * Creates a legal client
		 */
		public function createLegalClient($legalClient) {
			$pkRif = $legalClient -> getPkRif();
			$name = $legalClient -> getName();
			$emailAddress = $legalClient -> getEmailAddress();
			
			$connection = ConnectionFactory :: getMySqlConnectionAccessDao();
			$conn = $connection -> openConnection();
			
			$query = "INSERT INTO LEGAL_CLIENT VALUES ('$pkRif', '$name', '$emailAddress')";
			
			$sentence = mysql_query($query, $conn);
			
			if ($sentence)
				return 'true';
			
			$error = mysql_error($conn);
			
			$GLOBALS['debug'] -> log($error, "Error");
			
			return $error;
		}
		
		/**
		 * Selects a legal client by rif
		 */
		public function selectLegalClientByRif($rif) { 
			$connection = ConnectionFactory :: getMySqlConnectionAccessDao();
			$conn = $connection -> openConnection();
			
			$query = "SELECT name, email_address 
					  FROM LEGAL_CLIENT 
					  WHERE pk_rif = '$rif'";
			
			$sentence = mysql_query($query, $conn);
			
			$conn = $connection -> closeConnection($conn);
			
			return $sentence;
		}
	}
?>